﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hrAddPartTimePost.aspx.cs" Inherits="ZX.WebApp.EHR.hrAddPartTimePost" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
    body                    
    {                            
        font-family: 宋体, Arial, Helvetica, sans-serif;                            
        font-size: 12px;              
        color: #333333;                            
        background-color: #FFFFFF;                    
    }             
    select{width:99%;}                 
    .td_text                
    {               
        text-align:right;              
    }          
    .td_value          
    {              
        text-align:left;          
    }                 
    textarea                    
    {                            
        width: 98%;                    
    }	
    </style>
    <script src="../Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../Scripts/Public.js"></script>
    <script type="text/javascript" src="../Scripts/CombinButton.js"></script>
    <script type="text/javascript">
        var ValueChanged = function () { //部门发生变化后
            var deptId = $("#DeptId").val();
            getPostions(deptId,""); //获取该部门下所有岗位
        }

        //获取部门下的岗位
        function getPostions(deptID,postID) {
            $("#PostID").find('option').remove();
            var url = "../Extend/AjaxData/jsonlist.aspx?entity=DatPost&condition=DeptID='" + deptID + "'";
            $.get(url, function (d, s) {
                var list = eval("(" + d + ")");
                if (list.total == 0) {
                    $("#tishixinxi").text("该部门无岗位信息，请先维护部门岗位信息！");
                }
                else {
                    $("#tishixinxi").text("");
                    for (var o in list.rows) {
                        var v = list.rows[o].PostID;
                        var t = list.rows[o].PostName;
                        if (typeof (t) != "undefined") {
                            $("#PostID").append("<option value='" + v + "'>" + t + "</option>");
                        }
                    }
                    if (postID != "") {  //修改兼职岗位时
                        $("#PostID").attr("value", postID); //设置当前兼职岗位
                    }
                }
            });
        }

        //初始化
        if (typeof ($) != "undefined") {
            $(document).ready(function () {
                var deptName = getPar1("deptName");
                var postName = getPar1("postName");
                $("#mainDept").text(deptName);
                $("#mainPost").text(postName);
                var id = getPar1("id"); //hrEmployeePositions表中的ID
                if (typeof (id) != "undefined") //修改兼职岗位信息
                {
                    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployeePositionsPartTime&condition=ID='" + id + "'";
                    $.get(url, function (d, s) {
                        var list = eval("(" + d + ")");
                        if (list.total > 0) {
                            for (var o in list.rows) {
                                var v1 = list.rows[o].DeptID;
                                var t1 = list.rows[o].DeptName;
                                var v2 = list.rows[o].PostID;
                                var t2 = list.rows[o].PostName;
                                var vd = list.rows[o].ValidDate;
                                var fd = list.rows[o].FailDate;
                                if (typeof (v1) != "undefined" && typeof (v2) != "undefined") {
                                    $("#DeptId").val(v1); //部门ID
                                    $("#txtDeptId").val(t1); //部门名称
                                    $("#ValidDate").val(vd); //生效日期
                                    $("#FailDate").val(fd); //失效日期
                                    getPostions(v1,v2);//获取部门下岗位
                                    break;
                                }
                            }
                        }
                    });
                }
            });
        }

        //数据保存
        function Save() {
            var empId = getPar1("empId");
            var deptId = $("#DeptId").val();
            var postId = $("#PostID").val();
            if (postId == "") {
                alert("兼职岗位不能为空!");
                return;
            }
            var validDate = $("#ValidDate").val();
            if (validDate == "") {
                alert("生效日期不能为空!");
                return;
            }
            var failDate = $("#FailDate").val();
            if (failDate == "") {
                alert("失效日期不能为空!");
                return;
            }
//            //先检查该部门岗位是否有人在职，或有人兼职  ----暂时不做管控
//            YAHOO.util.Connect.asyncRequest('POST', "hrEmployeeAjax.aspx?flag=CheckPartTimePost&empId=" + empId + "&postId=" + postId + "&deptId=" + deptId, {
//                success: function (res) {
//                    try {
//                        var str = res.responseText;
//                        
//                    }
//                    catch (e) {
//                    }
//                    finally {
//                    }
//                },
//                failure: function (error) {
//                    alert("数据错误：" + error.statusText);
//                }
//            }, null);
            //提交数据
            if (empId != "") {
                var id = getPar1("id"); //hrEmployeePositions表中的ID
                var url="hrEmployeeAjax.aspx?flag=SavePartTimePost&empId=" + empId + "&postId=" + postId + "&validDate=" + validDate+"&failDate="+failDate+"&deptId="+deptId;
                if (id != "") {//修改数据时
                    url = "hrEmployeeAjax.aspx?flag=SavePartTimePost&empId=" + empId + "&postId=" + postId + "&validDate=" + validDate + "&failDate="+failDate+"&deptId=" + deptId + "&id=" + id;
                }
                YAHOO.util.Connect.asyncRequest('POST',url , {
                    success: function (res) {
                        try {
                        //debugger
                            var str = res.responseText;
                            if (str.substring(0, 1) == "0") {
                                alert("数据保存成功!");
                                parent.closeWin();
                                parent.ReLoadData();
                            }
                            else {
                                if (str == "-1") {
                                    alert("数据保存失败,请检查");
                                }
                                else if(str.substring(0,1)=="e") {
                                    alert("出现异动：" + str.substring(1, str.length - 1));
                                }
                            }
                        }
                        catch (e) {
                        }
                        finally {
                        }
                    },
                    failure: function (error) {
                        alert("数据错误：" + error.statusText);
                    }
                }, null);
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
	<input id="DeptId" name="DeptId" runat="server" type="hidden" />
	<table>
		<tbody>
			<tr>
				<td class="td_value" colspan="3">
					<div id="tishixinxi" style="color: #ff0000">
						&nbsp;</div>
				</td>
			</tr>
            <tr>
                <td class="td_text">
                    主职部门：
                </td>
                <td class="td_value">
                  <div id="mainDept"></div><br />
                </td>
                <td></td>
            </tr>
            <tr>
                <td class="td_text">
                    主职岗位：
                </td>
                <td class="td_value">
                  <div id="mainPost"></div><br />
                </td>
                <td></td>
            </tr>
			<tr>
				<td class="td_text">
					选择部门：</td>
				<td class="td_value">
					<input id="txtDeptId" name="txtDeptId" readonly="readonly" type="text" style="width: 152px"/><span style="color: #ff0000">*</span></td>
				<td class="td_text">
					<button class="btnCheck" id="btnDeptId" name="S" runat="server" style="width: 50px; height: 30px" type="button">选择</button></td>
			</tr>
			<tr>
				<td class="td_text">
					选择兼职岗位：</td>
				<td class="td_value">
					<select id="PostID" name="PostID" style="width: 156px" title=""></select><span style="color: #ff0000">*</span></td>
				<td class="td_text">
					&nbsp;</td>
			</tr>
			<tr>
				<td class="td_text">
					生效日期：</td>
				<td>
					<input class="Wdate" id="ValidDate" name="ValidDate" onclick="WdatePicker()" style="width: 152px" type="text" /><span style="color: #ff0000">*</span></td>
			</tr>
            <tr>
				<td class="td_text">
					失效日期：</td>
				<td>
					<input class="Wdate" id="FailDate" name="FailDate" onclick="WdatePicker()" style="width: 152px" type="text" /><span style="color: #ff0000">*</span></td>
			</tr>
		</tbody>
	</table>
</div>
    </form>
</body>
</html>
